Function Arguments

Arguments are passed by reference. Thus, when a function argument is modified, the object in the caller's scope gets modified directly. A function can be called with fewer arguments than specified in the definition. When this situation occurs, rlab pads the argument list with extra undefined variables. These undefined arguments can be detected with the exist function. Sometimes functions are written to use ``default'' values for arguments that are unspecified. For example: in ode78.r the argument variable tol is set to the ``default'' value of 1.e-6 if tol is UNDEFINED. Note that an undefined variable does not exist. Therefore, the exist function will return 0 if it's argument is undefined. There are two methods for invoking a function and specifiying undefined arguments. Either the arguments can be unspecified and the argument list will be padded with undefined variables, or the argument(s) can be explicitly specified as undefined by using a variable that is undefined. The variable UNDEF is commonly used for this, but the choice of undefined variable name(s) is arbitrary. A function cannot be called with more arguments than specified in the function definition. If you attempt to do so, a run-time error will result. Function argument types are not specified during definition. When writing ``robust'' functions the author should take some care to check that the function argument(s) are of the correct type. Furthermore, the documentation (comments) should clearly state the requisite argument types if necessary. If the function documentation does not clearly state that the arguments will be modified during function execution, care should be exercised to avoid changing any of the function arguments. If necessary, the function arguments can be copied to local variables, so that changes will not affect the caller's variables.